package com.open.party.cloud.view.home.jiCengDangJian.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.open.party.cloud.R;
import com.open.party.cloud.model.ZyzKaoQingBean;
import com.sinothk.android.utils.XUtils;

import java.util.ArrayList;
import java.util.List;

import com.sinothk.android.utils.inters.OnSuperListener;

public class ZyzQianDaoListAdapter extends RecyclerView.Adapter<ZyzQianDaoListAdapter.ViewHolder> {

    // 展示数据
    private ArrayList<ZyzKaoQingBean> mData;
    private Context mContext;
//    private OnSuperListener<ZyzKaoQingBean> onItemClickListener;

    public ZyzQianDaoListAdapter(Context mContext) {
        this.mContext = mContext;
        this.mData = new ArrayList<>();
    }

//    public void setOnItemViewEventListener(OnSuperListener<ZyzKaoQingBean> onItemClickListener) {
//        this.onItemClickListener = onItemClickListener;
//    }

    public void setData(List<ZyzKaoQingBean> data) {
        if (mData == null) {
            mData = new ArrayList<>();
        } else {
            mData.clear();
        }
        if (data == null) {
            data = new ArrayList<>();
        }
        this.mData.addAll(data);
        notifyDataSetChanged();
    }

    public void updateData(List<ZyzKaoQingBean> data) {
        this.mData.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public ZyzQianDaoListAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.zyz_kao_qing_list_item, viewGroup, false);
        return new ViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        // 绑定数据
        final ZyzKaoQingBean itemData = mData.get(position);

        holder.dayTv.setText(XUtils.string().getNotNullValue(itemData.getServiceDate()));
        holder.planTimeTv.setText("规定时间：" + XUtils.string().getNotNullValue(itemData.getServiceTime()));

        if (itemData.getCreateTime() == null) {
            holder.signTimeTv.setVisibility(View.INVISIBLE);
        } else {
            holder.signTimeTv.setVisibility(View.VISIBLE);
            holder.signTimeTv.setText("签到时间：" + XUtils.date().getDateStrByDate(itemData.getCreateTime(), "HH:mm:ss"));
        }

        if (itemData.getAddr() == null) {
            // 缺席无地址
            holder.locAddressView.setVisibility(View.GONE);
        } else {
            holder.locAddressView.setVisibility(View.VISIBLE);
            holder.locAddressTv.setText(XUtils.string().getNotNullValue(itemData.getAddr()));
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        LinearLayout rootView, locAddressView;
        TextView dayTv, signStatusTv, planTimeTv, signTimeTv, locAddressTv;

        ViewHolder(View itemView) {
            super(itemView);
            rootView = itemView.findViewById(R.id.rootView);
            locAddressView = itemView.findViewById(R.id.locAddressView);

            dayTv = itemView.findViewById(R.id.dayTv);
            signStatusTv = itemView.findViewById(R.id.signStatusTv);
            planTimeTv = itemView.findViewById(R.id.planTimeTv);
            signTimeTv = itemView.findViewById(R.id.signTimeTv);
            locAddressTv = itemView.findViewById(R.id.locAddressTv);
        }
    }
}